package cn.singleton.csl;

/**
 * Created by siyuzhiyue on 2017/6/9.
 */
public class Singleton1 {
    private static Singleton1 singleton1;
    private  int i = 0;
    private static int count = 0;
    private Singleton1(){
        System.out.println("此类被实例化第"+ ++count + "次！");
    }
    public static Singleton1 getSingleton1(){
        if(singleton1 == null)
            singleton1 = new Singleton1();
        return singleton1;
    }

    public void printMessage(){
        System.out.println(i++);
    }

    public static void main(String[] args){
        getSingleton1().printMessage();
        getSingleton1().printMessage();
        getSingleton1().printMessage();
    }
}
